Skip to content

Write push buttons that share a name as one field with each widget as a kid - #447

Merged
jakejackson1 merged 3 commits into
feature/pdfa-2-conformancefrom
fix/443-shared-button-names
Sep 23, 2026
Merged

jakejackson1 merged 3 commits into
feature/pdfa-2-conformancefrom
fix/443-shared-button-names

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Fixes #443

Push buttons that share a name are now written as one field, with each widget as a kid. Before, the second button's script replaced the first's, and then the second button had no action at all.

What changed

One field per shared name. Submit, reset, script and image buttons that share a name are written as one parent field: << /FT /Btn /Ff 65536 /T (go) /Kids [ … ] >>. This is the shape ISO 32000-1 §12.7.3.2 requires for two widgets that share a fully qualified name.

  • The parent is a field, not an annotation. /AcroForm /Fields lists it, and no page's /Annots does.
  • Each kid is still listed in its page's /Annots. It has a /Parent and no /T, and keeps its own /MK caption and icon, /AA action, /TU and /AP.
  • This follows the radio-group pattern. Form::addButtonGroupIds() numbers the parents in MetadataWriter::numberAnnotations(), after the radio groups. Form::putButtonGroups() writes them after _putRadioItems().
  • The groups are built from $forms at output time, not when each button is set. Only buttons that actually made it onto a page are counted: a block measured for page-break-inside: avoid and then drawn again contributes each button once.
  • A named button in an HTML header becomes one field with a widget on every page.

Scripts and icons are keyed by the button, not its name.

  • array_form_button_js and form_button_icon are now keyed by the button's form number ($form['n']), so a second button no longer overwrites the first's entry.
  • The script is no longer unset() after the first widget uses it.
  • SetFormButtonJS() now takes that number instead of a name. Its only caller is SetJSButton().

Unchanged:

  • A button whose name no other button uses keeps today's merged field and widget with /T.
  • Text and choice fields that share a name are out of scope, as the issue says.
  • Unnamed buttons are not touched. On this branch an unnamed submit or reset still falls back to Submit or Reset, so two of them are now gathered like any other shared name. Once Give a button with no name a name of its own #438 gives them distinct names, they stay separate fields.

Snapshots

None changed. BasicHtmlSnapshotTest has four buttons named submit, but it doesn't turn on useActiveForms, so it draws static buttons. The form-fields-* fixtures give every button a different name.

Verification

  • New tests/Mpdf/SharedButtonNameTest.php (7 tests; all fail without the fix except the import check):
    • the issue's example gives one parent with /T (go) and two kids, the kids have no /T, and each runs its own script;
    • submit, reset, script and image buttons with one name gather into one field, while a lone button stays a single widget with /T;
    • two image inputs with one name keep their own icons (landscape and portrait);
    • under PDF/A-2b the grouping is the same, with no /AA and no /JS;
    • buttons in a page-break-inside: avoid block that moves to the next page are gathered once each;
    • a header button is one field with a kid on each page;
    • the output still imports with setSourceFile() / importPage().
  • AnnotationObjectNumbersTest adds two buttons named go on page 1 and one on page 2, image buttons named b on both pages, and a lone reset. It checks, under every setup (including PDF/A-2b), that:
    • every /Parent lists its kid;
    • kids have no /T;
    • the four parents (two radio groups, two button groups) are in /Fields and in no /Annots;
    • every object number below /Size is written.
  • PdfaConformanceTest::testActiveFormConforms gains a second button named b. veraPDF passes the conformance group: 29 tests, across 1-B, 2-B, 2-U, 3-B and 3-U with sRGB and CMYK intents.
  • Rendering: I rendered the issue's example plus a lone button with pdftoppm and Ghostscript. All three captions draw. pdfinfo -js shows each widget with its own script. pypdf finds the fields go and lone.
  • Gates:
    • composer test: 3779 tests OK, the usual 5 skips.
    • --group=snapshot: 89 OK.
    • composer cs: clean.
    • PHPStan 2.2: no errors. The baseline count for $js in isset() in Form.php drops from 2 to 1.
    • php -l under PHP 5.6: clean on every changed file.

Upstream (create-upstream-pr)

The name-keyed JS and icon lookups and the duplicate /T are the same on mpdf/mpdf development, and the fix carries over. Two parts depend on this branch and need adapting there:

Limits

  • Same-named text and choice fields still share name-keyed array_form_text_js and array_form_choice_js and a duplicate /T. They need a decision of their own, as the issue says.
  • The radio-group parent is still written as a zero-size /Widget annotation (existing code). The new button parent is a plain field.

🤖 Generated with Claude Code

jakejackson1 and others added 3 commits September 23, 2026 22:09
… a kid

Same-named submit, reset, script and image buttons were written as separate
fields with the same /T, and their script and icon were looked up by name, so
the second button's script replaced the first's and was then used up. Each
group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in
/AcroForm /Fields but in no page's /Annots, and its widgets keep their own
action, caption, icon and appearance under a /Parent. Scripts and icons are
keyed by the button's form number.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…per, and write the push-button flag as the widgets do

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1 jakejackson1 added bug Something isn't working create-upstream-pr labels Sep 23, 2026
@jakejackson1
jakejackson1 merged commit 543906b into feature/pdfa-2-conformance Sep 23, 2026
29 checks passed
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
… a kid (#447)

* Write push buttons that share a name as one field with each widget as a kid

Same-named submit, reset, script and image buttons were written as separate
fields with the same /T, and their script and icon were looked up by name, so
the second button's script replaced the first's and was then used up. Each
group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in
/AcroForm /Fields but in no page's /Annots, and its widgets keep their own
action, caption, icon and appearance under a /Parent. Scripts and icons are
keyed by the button's form number.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Read the reference lists in the shared button name tests with one helper, and write the push-button flag as the widgets do

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Say what a push button is where the shared button name code asks

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
#441 moved SetJSButton()'s SetFormButton() call below the icon, so that the
field knows it shows one, and #447 keyed the icon by $this->formCount, which
is the button's number only once SetFormButton() has counted it. Merged
together, each icon went to the form before it: the widget lost its icon, the
object count reserved one that was never written, and SetFormButton() still
looked the icon up by name. The icon is now kept under the number the button
is about to get, and SetFormButton() looks for it there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
… a kid (#447)

* Write push buttons that share a name as one field with each widget as a kid

Same-named submit, reset, script and image buttons were written as separate
fields with the same /T, and their script and icon were looked up by name, so
the second button's script replaced the first's and was then used up. Each
group is now a parent field (/FT /Btn, push-button flag, /T, /Kids) listed in
/AcroForm /Fields but in no page's /Annots, and its widgets keep their own
action, caption, icon and appearance under a /Parent. Scripts and icons are
keyed by the button's form number.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Read the reference lists in the shared button name tests with one helper, and write the push-button flag as the widgets do

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Say what a push button is where the shared button name code asks

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1 added a commit that referenced this pull request Sep 23, 2026
#441 moved SetJSButton()'s SetFormButton() call below the icon, so that the
field knows it shows one, and #447 keyed the icon by $this->formCount, which
is the button's number only once SetFormButton() has counted it. Merged
together, each icon went to the form before it: the widget lost its icon, the
object count reserved one that was never written, and SetFormButton() still
looked the icon up by name. The icon is now kept under the number the button
is about to get, and SetFormButton() looks for it there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@jakejackson1
jakejackson1 deleted the fix/443-shared-button-names branch September 30, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant